#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
#include <string>
#define int long long
#define x first
#define y second
#include <sstream>

using namespace std;

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        if (nums.size() < 3)
            return 0;
        sort(nums.begin(), nums.end());

        int left = 0, right = nums.size() - 2, pos = right + 1, count = 0;
        while (right != left)
        {

            while (right != left)
            {
                if (nums[left] + nums[right] > nums[pos])
                {
                    count += right - left;
                    right--;
                }
                else
                {
                    left++;
                }
            }
            pos--;
            right = pos - 1;
            left = 0;
        }
        return count;
    }
};

class Solution1 {
    int m, n;
    int x[4] = { 1,-1,0,0 }, y[4] = { 0,0,1,-1 };
    bool Hash[301][301];
public:
    void dfs(vector<vector<char>>& grid, int ii, int jj)
    {
        Hash[ii][jj] = 1;
        for (int k = 0; k < 4; k++)
        {
            int i = ii + x[k];
            int j = jj + y[k];
            if (i >= 0 && i < m && j >= 0 && j < n && !Hash[i][j] && grid[i][j] == '1')
                dfs(grid, i, j);
        }

    }
    int numIslands(vector<vector<char>>& grid) {
        memset(Hash, 0, sizeof(Hash));
        int count = 0;
        m = grid.size();
        n = grid[0].size();
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
            {
                if (!Hash[i][j] && grid[i][j] == '1')
                {
                    count++;
                    dfs(grid, i, j);
                }
            }
        return count;
    }
};

void solve()
{
    int a, b;
    cin >> a >> b;
    vector<vector<char>> ret(b);
    for (int i = 0; i < b; i++)
    {
        ret[i] = vector<char>(a);
        for (int j = 0; j < a; j++)
        {
            cin >> ret[i][j];
        }
    }
    Solution1 s;
    cout << s.numIslands(ret) << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    while(t -- )  solve();
}